
*5) Country characteristics by BLA signing in the past 10 years

	*a) country characteristics

	use nat_BLA_data_1945_2020, clear

	tsset code year

	forval i = 1/10 {
	
		gen l`i'_bla_any = L`i'.bla_any
		
	}
	
	egen bla_any_past10 = rowmax(bla_any l?_bla_any l??_bla_any)
	
	gen pc_rgdpe = rgdpe/pop
	gen emp_rate = emp/pop
	gen trade_share = (imports_all+exports_all)/(pl_gdpo*cgdpo*1000000)
	
	*BLA signers
	cap mat drop sum_nat_bla1
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		qui sum `var' if bla_any_past10==1, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat rownames tempsum = `var'
		mat sum_nat_bla1 = nullmat(sum_nat_bla1)\tempsum
		
	}
	
	*BLA non-signers
	cap mat drop sum_nat_bla0
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		qui sum `var' if bla_any_past10==0, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat sum_nat_bla0 = nullmat(sum_nat_bla0)\tempsum
		
	}
	
	mat sum_nat = sum_nat_bla1,sum_nat_bla0
	
	*Count
	count if bla_any_past10==1
	scalar count_nat_bla1 = `r(N)'
	
	count if bla_any_past10==0
	scalar count_nat_bla0 = `r(N)'
	
	*Effect sizes
	gen bla_any_past10_rev = bla_any_past10 //replacing 0 with 2 so we get the right sign
	replace bla_any_past10_rev = 2 if bla_any_past10==0
	
	cap mat drop esizes_mat
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		esize twosample `var', by(bla_any_past10_rev)
		mat tempsum = [`r(d)', `r(lb_d)', `r(ub_d)']
		mat rownames tempsum = `var'
		mat esizes_mat = nullmat(esizes_mat)\tempsum
		
	}
	
	*b) dyad characteristics

	use dyad_BLA_data_1945_2020, clear

	tsset dyad_id year

	forval i = 1/10 {
	
		gen l`i'_bla_any = L`i'.bla_any
		
	}
	
	egen bla_any_past10 = rowmax(bla_any l?_bla_any l??_bla_any)
	
	gen pc_rgdpeA = rgdpeA/popA
	gen pc_rgdpeB = rgdpeB/popB
	gen pc_rgdpe_diff = abs(pc_rgdpeA-pc_rgdpeB)
	
	gen emp_rateA = empA/popA
	gen emp_rateB = empB/popB
	gen emp_rate_diff = abs(emp_rateA-emp_rateB)
	
	gen polity2_diff = abs(polity2A-polity2B)
	
	*Identifying "host"
	sort dyad_id year
	by dyad_id: gen gdpnonmiss = _n if !missing(pc_rgdpe_diff)
	by dyad_id: egen mingdpnonmiss = min(gdpnonmiss)
	
	gen first_host = codeA if pc_rgdpeA>pc_rgdpeB & !missing(pc_rgdpe_diff) & gdpnonmiss==mingdpnonmiss
	replace first_host = codeB if pc_rgdpeA<pc_rgdpeB & !missing(pc_rgdpe_diff) & gdpnonmiss==mingdpnonmiss
	
	by dyad_id: egen code_host = max(first_host)
	kountry code_host, from(cown) geo(men)
	gen MENA_host = GEO=="Middle East"
	drop GEO NAMES
	
	*GDP difference for MENA vs. non-MENA hosts
	gen pc_rgdpe_diff_MENA = pc_rgdpe_diff if MENA_host==1
	gen pc_rgdpe_diff_notMENA = pc_rgdpe_diff if MENA_host==0
	
	*GDP per capita ratio host to source
	gen pcgdp_ratio_host_source = ln(pc_rgdpeA)/ln(pc_rgdpeB) if codeA==code_host
	replace pcgdp_ratio_host_source = ln(pc_rgdpeB)/ln(pc_rgdpeA) if codeB==code_host
	
	*Higher Polity2 score in source
	gen higher_polity2_source = 0 if !missing(polity2A) & !missing(polity2B)
	replace higher_polity2_source = 1 if ((polity2A>polity2B & codeB==code_host) | (polity2A<polity2B & codeA==code_host)) & !missing(higher_polity2_source)
	
	*Treaty onset
	sort dyad_id year
	by dyad_id: gen onset = bla_past - bla_past[_n-1]
	replace onset = 0 if onset==.
	gen after_onset = onset==0 & bla_past==1
	
	*Time
	gen time = year-1945
	gen time_2 = time^2
	gen time_3 = time^3
	
	*Regressions to replicate Table 3 in Chilton/Posner
	#delimit ;
	
		local controls `"
		"c.pcgdp_ratio_host_source"
		"1.higher_polity2_source"
		"c.pcgdp_ratio_host_source 1.higher_polity2_source"
		"c.pcgdp_ratio_host_source 1.MENA_host 1.MENA_host#c.pcgdp_ratio_host_source"
		"1.higher_polity2_source 1.MENA_host 1.higher_polity2_source#1.MENA_host"
		"c.pcgdp_ratio_host_source 1.MENA_host 1.MENA_host#c.pcgdp_ratio_host_source
			1.higher_polity2_source 1.higher_polity2_source#1.MENA_host"
		"';
	
	#delimit cr
	
	local i = 1
	
	foreach c in `controls' {
	 
		di "`c'"
		qui logit onset `c' time time_2 time_3 if after_onset==0, vce(cl dyad_id)
		
		est store est`i++'
		
		
	}
	
	#delimit ;

	esttab est1 est2 est3 est4 est5 est6 using reg_chilton_posner, 
		keep(pcgdp_ratio_host_source 1.higher_polity2_source 1.MENA_host#c.pcgdp_ratio_host_source
		1.higher_polity2_source#1.MENA_host 1.MENA_host) 
		order(pcgdp_ratio_host_source 1.higher_polity2_source 1.MENA_host#c.pcgdp_ratio_host_source
		1.higher_polity2_source#1.MENA_host 1.MENA_host)
		coeflab(pcgdp_ratio_host_source "GDP per Capita Raio (host/source)" 1.higher_polity2_source
		"Higher Source Polity Score" 1.MENA_host#c.pcgdp_ratio_host_source "GDP per Capita Ratio \(\times\) Middle Eastern Host"
		1.higher_polity2_source#1.MENA_host "Higher Source Polity Score \(\times\) Middle Eastern Host" 1.MENA_host "Middle Eastern Host")
		b(3) se(3) booktabs label nolegend nonotes replace star(* 0.1 ** 0.05 *** 0.01)
		stats(r2_p N, labels("\(Pseudo-R^2\)" "\(N\)") fmt(3 0)) f nomtitles nonumbers 
		prehead("\begin{table}[!htbp]
		\fontsize{9}{10}\selectfont
		\caption{Treaty onset}
		\begin{tabularx}{\textwidth}{p{6cm}XXXXXX}
		\toprule
		& (1) & (2) & (3) & (4) & (5) & (6) \\")
		postfoot("\bottomrule 
		\addlinespace
		\multicolumn{7}{p{\textwidth}}{\fontsize{9}{10}\selectfont \textbf{Note}:}
		\end{tabularx}
		\end{table}");
			
	#delimit cr	
	